const path = require('path');
const Config = require('./config.path');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
    mode: 'development',
    entry: {
        main: "./src/js/index.js",
    },
    output: {
        path: path.resolve(__dirname, './dist/ossweb-img/'),
        filename: '[name].js',
        publicPath: Config.handover
    },
    module: {
        rules: [{
                test: /\.js$/,
                include: [
                    path.resolve(__dirname, 'src')
                ],
                use: [{
                        loader: 'babel-loader'
                    }
                    // ,{
                    //   loader: 'file-loader' ,
                    //   options: {
                    //     name: '[hash][name].[ext]',
                    //     outputPath: 'js/'
                    //   }
                    // }
                ]
            },
            {
                test: /\.(png|jpg|gif)$/,
                use: [{
                    loader: 'url-loader',
                    options: {
                        limit: 1024,
                        name: '[name].[ext]',
                        // outputPath: ''
                    }
                }]
            },
            {
                test: /\.less$/,
                use: ExtractTextPlugin.extract({
                    fallback: 'style-loader',
                    use: ['css-loader', 'less-loader']
                })
                // ,
                //   use: [{ loader: 'style-loader' }, { 
                //     loader: 'css-loader' },{
                //     loader: 'less-loader',
                //     options: {
                //       outputPath: 'css/'
                //     }
                // }]
            },
            {
                test: /js[\/|\\]lib[\/||\\][\w|\.|_|-]+js$/,
                use: 'url-loader?limit=1000&name=./lib/[name].[ext]'
            },
            {
                test:/.vue$/,
                loader: 'vue-loader'
            }
        ]
    },
    plugins: [
        new CleanWebpackPlugin('dist'),
        new ExtractTextPlugin('./[name].css'),
        new UglifyJsPlugin(),
        new HtmlWebpackPlugin({
            filename: '../index.html',
            template: 'index.html'
        })
    ]
}